package com.ticket.sass.common.entity.tenant.enums

import com.baomidou.mybatisplus.annotation.IEnum


enum class JumpType(private val value: Short, private val tips: String) : IEnum<Short> {
    NONE(0, "无跳转"),
    INSIDE(1, "内部页面"), // 参数 routeType 1 切换页面 2 跳转页面
    MINI_PROGRAM(2, "无跳转"),
    HTML(3, "网页");

    override fun getValue(): Short {
        return value
    }

    companion object {
        fun valueOf(v: Short) = values().find { it.value == v } ?: error("未匹配到枚举")
    }

    open fun isJumpConfigValid(jumpConfig: Map<String?, Any?>?): Boolean {
        return if (jumpConfig == null) {
            this === NONE
        } else when (this) {
            NONE -> jumpConfig.isEmpty()
            INSIDE -> jumpConfig.containsKey("path") &&
                    jumpConfig.containsKey("routeType") &&
                    (jumpConfig["routeType"] == 1 || jumpConfig["routeType"] == 2) && jumpConfig.size == 2

            MINI_PROGRAM -> jumpConfig.containsKey("path") &&
                    jumpConfig.containsKey("appid") &&
                    jumpConfig.containsKey("shortLink") && jumpConfig.size == 3

            HTML -> jumpConfig.containsKey("title") &&
                    jumpConfig.containsKey("url") && jumpConfig.size == 2

            else -> false
        }
    }

}